﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace SportManager
{
    /// <summary>
    /// Type of exercise
    /// </summary>
    public enum ExerciseType
    {
        Power = 0,
        Aerobics
    }

    /// <summary>
    /// Muscle group
    /// </summary>
    public enum ExerciseLoad
    {
        None = 0,
        Back,
        Chest,
        Hands,
        Legs,
        Press,
        Shoulders
    }

    /// <summary>
    /// Information about exercise
    /// </summary>
    [Serializable]
    public class ExerciseInfo : DataHolder
    {
        public ExerciseInfo(String name, String description, ExerciseType type, List<ExerciseLoad> load)
        {
            Name = name;
            Description = description;
            Type = type;
            Load = load;
            Id = Guid.NewGuid();
            Update();
        }

        public override string ToString()
        {
            return Name;
        }

        public String GetLoadsListString()
        {
            System.Text.StringBuilder loads = new System.Text.StringBuilder();
            string separator = "";
            foreach (ExerciseLoad item in Load)
            {
                loads.Append(separator);
                loads.Append(item.EnumToString());

                if (separator.Length == 0)
                {
                    separator = ", ";
                }
            }

            return loads.ToString();
        }

        #region ExerciseInfo fields
        private String m_name;
        private String m_description;
        private List<ExerciseLoad> m_load;
        private ExerciseType m_type;
        private bool m_userDefined;
        private bool m_isRepeatsRequired;
        private bool m_isApproachRequiered;
        private bool m_isRepeatsRestRequiered;
        private bool m_isApproachsRestRequired;
        private bool m_isTempoRequired;
        private bool m_isTimeSpanRequired;
        private bool m_isIntensityRequired;
        private bool m_isWeightRequired;
        private bool m_isDistanceRequired;
        #endregion

        #region ExerciseInfo properties
        /// <summary>
        /// The name of Exercise
        /// </summary>
        public String Name 
        {
            get
            {
                return m_name;
            }
            set
            {
                m_name = value;
                Update();
            }
        }
        /// <summary>
        /// Exercise Description
        /// </summary>
        public String Description
        {
            get
            {
                return m_description;
            }
            set
            {
                m_description = value;
                Update();
            }
        }
        /// <summary>
        /// Muscle group
        /// </summary>
        public List<ExerciseLoad> Load
        {
            get
            {
                return m_load;
            }
            set
            {
                m_load = value;
                Update();
            }
        }
        /// <summary>
        /// The type of Exercise
        /// </summary>
        public ExerciseType Type
        {
            get
            {
                return m_type;
            }
            set
            {
                m_type = value;
                Update();
            }
        }
        /// <summary>
        /// Is this user defined exerces
        /// </summary>
        public bool IsUserDefined
        {
            get
            {
                return m_userDefined;
            }
            set
            {
                m_userDefined = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed repeats for this exercise
        /// </summary>
        public bool IsRepeatsRequired
        {
            get
            {
                return m_isRepeatsRequired;
            }
            set
            {
                m_isRepeatsRequired = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed approachs for this exercise
        /// </summary>
        public bool IsApproachRequiered
        {
            get
            {
                return m_isApproachRequiered;
            }
            set
            {
                m_isApproachRequiered = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed rest between repeats
        /// </summary>
        public bool IsRepeatsRestRequiered
        {
            get
            {
                return m_isRepeatsRestRequiered;
            }
            set
            {
                m_isRepeatsRestRequiered = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed rest between approachs
        /// </summary>
        public bool IsApproachsRestRequired
        {
            get
            {
                return m_isApproachsRestRequired;
            }
            set
            {
                m_isApproachsRestRequired = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed tempo for this exercise
        /// </summary>
        public bool IsTempoRequired
        {
            get
            {
                return m_isTempoRequired;
            }
            set
            {
                m_isTempoRequired = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed time span for this exercise
        /// </summary>
        public bool IsTimeSpanRequired
        {
            get
            {
                return m_isTimeSpanRequired;
            }
            set
            {
                m_isTimeSpanRequired = value;
                Update();
            }
        }
        /// <summary>
        /// Is internsity required for this exrcise
        /// </summary>
        public bool IsIntensityRequired
        {
            get
            {
                return m_isIntensityRequired;
            }
            set
            {
                m_isIntensityRequired = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed weight for this exercise
        /// </summary>
        public bool IsWeightRequired
        {
            get
            {
                return m_isWeightRequired;
            }
            set
            {
                m_isWeightRequired = value;
                Update();
            }
        }
        /// <summary>
        /// Is it needed distance for this exercise
        /// </summary>
        public bool IsDistanceRequired
        {
            get
            {
                return m_isDistanceRequired;
            }
            set
            {
                m_isDistanceRequired = value;
                Update();
            }
        }
        #endregion
    }

    #region Extensions for enums
    public static class Extensions
    {
        public static String EnumToString(this ExerciseType type)
        {
            switch (type)
            {
                case ExerciseType.Aerobics:
                    {
                        return "Аэробные упражнения";
                    }
                case ExerciseType.Power:
                    {
                        return "Силовые упражнения";
                    }
                default:
                    {
                        throw new Exception("Wrong Exercise type!");
                    }
            }
        }

        public static String EnumToString(this ExerciseLoad load)
        {
            switch (load)
            {
                case ExerciseLoad.Back:
                    {
                        return "Спина";
                    }
                case ExerciseLoad.Chest:
                    {
                        return "Грудь";
                    }
                case ExerciseLoad.Hands:
                    {
                        return "Руки";
                    }
                case ExerciseLoad.Legs:
                    {
                        return "Ноги";
                    }
                case ExerciseLoad.None:
                    {
                        return "";
                    }
                case ExerciseLoad.Press:
                    {
                        return "Живот";
                    }
                case ExerciseLoad.Shoulders:
                    {
                        return "Плечи";
                    }
                default:
                    {
                        throw new Exception("Wrong Exercise load!");
                    }
            }
        }
    }
    #endregion
}